package com.spsyry.order.controller;

import com.alibaba.fastjson2.JSON;
import com.spsyry.api.pay.PayApi;
import com.spsyry.api.vo.AddOrderVo;
import com.spsyry.common.core.domain.R;
import com.spsyry.order.domain.Order;
import com.spsyry.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private PayApi payApi;

    @PostMapping(value = "/create",consumes = MediaType.APPLICATION_JSON_VALUE)
    public R createOrder(@RequestBody AddOrderVo addOrderVo) throws Exception{

        log.info("订单系统-参数：addOrderVo：{}", JSON.toJSONString(addOrderVo));

        int i = iOrderService.insertOrder(Order.builder().orderNo(addOrderVo.getOrderId()).userId(Long.valueOf(addOrderVo.getUserId())).totalAmount(addOrderVo.getPrice()).orderStatus(90).build());
//        int p = iOrderService.insertOrder(Order.builder().orderNo(addOrderVo.getOrderId()).userId(Long.valueOf(addOrderVo.getUserId())).totalAmount(addOrderVo.getPrice()).orderStatus(90).build());

        R r = payApi.createOrder(addOrderVo);

        return r;
    }

}